

import java.math.BigDecimal;

/**
 * @author Ye Lanyi
 * @version 1.0
 */
public abstract class Card {

    private String nameOfMirror;
    private BigDecimal price;
    private CardType cardType;

    public abstract void pay(BigDecimal amount);

    public String getNameOfMirror() {
        return nameOfMirror;
    }

    public CardType getCardType() {
        return cardType;
    }

    public void setCardType(CardType cardType) {
        this.cardType = cardType;
    }

    public void setNameOfMirror(String nameOfMirror) {
        this.nameOfMirror = nameOfMirror;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    // 提取公共折扣计算逻辑
    public BigDecimal calculateDiscount(BigDecimal amount) {
        return amount.multiply(BigDecimal.valueOf(getDiscountRate()));
    }
    
    protected abstract double getDiscountRate();
    
    // 添加通用验证方法
    protected void validateAmount(BigDecimal amount) {
        if (amount.compareTo(BigDecimal.ZERO) <= 0) {
            throw new IllegalArgumentException("Amount must be positive");
        }
    }
}
